package com.hwadee.hello.service.impl;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hwadee.hello.dao.StudentDao;
import com.hwadee.hello.entity.Student;
import com.hwadee.hello.mapper.StudentMapper;
import com.hwadee.hello.service.StudentService;
@Component
public class StudentServiceImpl implements StudentService {
	@Autowired
	private StudentMapper studentMapper;
	
	//private Map<String,Student> students;
	private Date date;
	private List<Student> list;
	private Map map;
	private PageInfo<Student> students;
	
	
	public void setMap(Map map) {
		this.map = map;
	}


	public void setDate(Date date) {
		this.date = date;
	}


	public void setList(List list) {
		this.list = list;
	}


	@Override
	public String toString() {
		return "StudentService [studentMapper=" + studentMapper + ", students=" + students + ", date=" + date + ", list="
				+ list + "]";
	}


	/*
	 * public void setStudents(Map<String,Student> students) { this.students =
	 * students; }
	 */

	public void setStudentDao(StudentMapper studentMapper) {
		System.out.println("type");
		this.studentMapper = studentMapper;
	}
	
	public int add(Student stu){
		
		return studentMapper.insert(stu);
	}
	
	@Transactional
	public int transfer(int a, int b, int age) {
		studentMapper.updatingAge(b, age);
		studentMapper.updatingAge(a, -age);
		
		return 1;
	}
	
	public int test(int arg) {
		System.out.println("---test---");
		return arg+1;
	}
	
	@Override
	public PageInfo<Student> getStudents(int p){
		PageHelper.startPage(p, 3);
		List<Student> students = studentMapper.findAll();
		
		return new PageInfo<Student>(students);
	}


	@Override
	public int removeStudent(int id) {
		return studentMapper.delete(id);
	}


	@Override
	public int update(Student stu) {
		return studentMapper.update(stu);
	}


	@Override
	public Student findById(int id) {
		return studentMapper.findById(id);
	}
	
}
